<?PHP

require_once ('../includes/global.php');
// echo '{success:true,msg:\''.$_POST['randCode'].'\'}';
#echo $_SESSION['yzm'];exit;

/**
 * 多维数组过滤
 * ---主要是删除功能
 * @param type $array
 * @param type $callback
 * @return type
 */
function array_merge_bic($array, $array2) {
    $ret = array();
    foreach ($array2 as $key => $value) {
        if (is_array($value)) {
            $array[$key] = array_merge_bic($array[$key], $value);
        } elseif (is_object($value)) {
            $array[$key] = array_merge_bic($array[$key], get_object_vars($value));
        } else {
            if (is_array($array[$key])) {
                $value = $array[$key];
                $array[$key] = array_merge_bic($array[$key], $value);
            } else {
                if ($value > 0) {
                    $array[$key] = $value;
                }
            }
        }
    }
    return $array;
}

if ($_POST['action'] == 'loginz') {
    /* if (trim(strtolower($_POST['randCode'])) != strtolower($_SESSION['yzm'])) {
      echo '{success:true,msg:\'验证码错误，请重新输入，区分大小写！<BR>Authcode error, please enter again, case-sensitive!\'}';
      exit;
      } */
    $userinfo = Dgd(array(
        'db' => 'd_sevenel',
        'tn' => "user",
        'cd' => "user = '" . trim($_POST[username]) . "' and psw = '" . md5($_POST[password]) . "' and del != '1'",
        'limit' => 1
            ));
    if ($userinfo) {
        $_SESSION['LG'] = ($_POST[LG] == 'bg') ? "zh" : $_POST[LG];
        $_SESSION['LG'] == '' && $_SESSION['LG'] = 'zh';
        $_SESSION['XS'] = $_POST[LG];
        $_SESSION['logined'] = 1;
        $_SESSION['userinfo'] = $userinfo;

        $rcfgs = explode(',', $userinfo['rcfg']);
        $value;
        $rcfg = array();
        foreach ($rcfgs as $v) {

            $tmp = Dgd(array(
                'db' => 'd_sevenel',
                'tn' => 'rtp',
                'cd' => " id = '" . $v . "' ",
                'limit' => 1
                    ));
            //Jc(json_decode($tmp['cfg'], true));
            //Jc($rcfg);
            $rcfg = array_merge_bic($rcfg, json_decode($tmp['cfg'], true));
            //$rcfg = json_decode($tmp['cfg'], true);
        }
        //Jc($rcfg);

        $tq = Dgd(array(
            'db' => 'd_sevenel',
            'tn' => 'rtp',
            'cd' => " id = '" . $userinfo['rcfg'] . "' ",
            'limit' => 1
                ));
        if ($_POST['user'] == 'admin') {
            $_SESSION['rcg'] = 'A';
        } else {
            $_SESSION['rcg'] = $rcfg;
        }
        $plugin = Plugin::init();
        $plugin->trigger('login_after', $_POST);
        echo '{success:true,msg:\'ok\'}';
    } else {
        echo '{success:true,msg:\'帐户或密码错误,请重新输入！<br>Account or password mistake, please enter again!\'}';
    }
}
?>